#include <stdio.h>
#include <string.h>
#include <stdlib.h>


void *my_memcpy(void *dest, const void *src, unsigned short count); 
int main()
{
    char buffer[50];
    int j = snprintf(buffer, 6, "%s\n", "123obcom");
    printf("string:%s character count = %d\n", buffer, j);
    char valrchar_one[2];
    memset(valrchar_one,0,2);
    my_memcpy(valrchar_one, buffer, 2);
    printf("valrchar one0:%c\n",valrchar_one[0]);
    printf("valrchar one1:%c\n",valrchar_one[1]);
    char i = 0; 
    for (; i < 9; i++)
    {
         printf("valrchar_one-%d:%c\n",i,valrchar_one[i]);
    }

    printf("valrchar_one %c\n",valrchar_one[0]);
    // int k =snprintf(valrchar_one,1,"%s",buffer);
    printf("\n%x    buffer[1]:%x buffer[1]x:%c\n", valrchar_one[0], buffer[1], buffer[1]);

#if 0
i=0;
char valrChar[10];
memset(valrChar,0,sizeof(valrChar));
strcat(valrChar,valrchar_one);
int count = sizeof(valrChar);
printf("sizeof valrchar:%d\n",count);

for (; i < count-1; i++)
{
    printf("valrChar--%c\n",valrChar[i]);
}
 i= 0;
for (; i < count-1; i++)
{
    printf("valrchar_one--%c\n",valrchar_one[i]);
}
#endif

    return 0;
}

void test_01(void){
    #if 1
   #else
    valrchar_one[0] = buffer[0];
    memset(valrchar_one, 0, 1);
    memcpy_s(valrchar_one, sizeof(valrchar_one), buffer, 1);
    char *charstr;
    charstr = malloc(2);
    strncpy(charstr, valrchar_one, 1);
    charstr[1] = '\0';
    printf("charstr:%s\n", charstr);
#endif

}


void *my_memcpy(void *dest, const void *src, unsigned short count)  
{  
  unsigned char *pdest = (unsigned char *)dest;  
  const unsigned char *psrc  = (const unsigned char *)src;  
  unsigned short i;
  
  if(dest == NULL || src == NULL)
  { 
    return NULL;
  }
  
  if((pdest <= psrc) || (pdest > psrc + count))
  {  
    for(i = 0; i < count; i ++)
    {  
      pdest[i] = psrc[i];  
    }  
  }
  else
  {
    for(i = count; i > 0; i --)
    {  
      pdest[i - 1] = psrc[i - 1];  
    }  
  }  
  
  return dest;  
}